﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MokaType", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MokaType))]
    public class MokaTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMokaType clazz;
        
        public MokaTypeSerializer(IMokaType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Treasury");
            if (clazz.Treasury!=null) {
                global::Xtee.Core.SerializationMetadata metaTreasury = this.GetMetaData(clazz.Treasury);
                Writer.WriteTypeAttribute(metaTreasury.TypeQualifiedName.Namespace, metaTreasury.TypeQualifiedName.Name);
                metaTreasury.NewSerializer(clazz.Treasury).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Treasury");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Payer");
            if (clazz.Payer!=null) {
                global::Xtee.Core.SerializationMetadata metaPayer = this.GetMetaData(clazz.Payer);
                Writer.WriteTypeAttribute(metaPayer.TypeQualifiedName.Namespace, metaPayer.TypeQualifiedName.Name);
                metaPayer.NewSerializer(clazz.Payer).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Payer");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Receiver");
            if (clazz.Receiver!=null) {
                global::Xtee.Core.SerializationMetadata metaReceiver = this.GetMetaData(clazz.Receiver);
                Writer.WriteTypeAttribute(metaReceiver.TypeQualifiedName.Namespace, metaReceiver.TypeQualifiedName.Name);
                metaReceiver.NewSerializer(clazz.Receiver).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Receiver");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Payment");
            if (clazz.Payment!=null) {
                global::Xtee.Core.SerializationMetadata metaPayment = this.GetMetaData(clazz.Payment);
                Writer.WriteTypeAttribute(metaPayment.TypeQualifiedName.Namespace, metaPayment.TypeQualifiedName.Name);
                metaPayment.NewSerializer(clazz.Payment).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Payment");
            }
            Writer.WriteEndElement();
            if (clazz.TreasuryClassif!=null) {
                Writer.WriteStartElement("TreasuryClassif");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TreasuryClassif))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.PaymentDesc!=null) {
                Writer.WriteStartElement("PaymentDesc");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>MokaType>PaymentDesc");
                Writer.WriteString(clazz.PaymentDesc.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "Treasury")) {
                goto Treasury;
            }
            else {
                if ((Reader.LocalName == "Payer")) {
                    goto Payer;
                }
                else {
                    if ((Reader.LocalName == "Receiver")) {
                        goto Receiver;
                    }
                    else {
                        if ((Reader.LocalName == "Payment")) {
                            goto Payment;
                        }
                        else {
                            if ((Reader.LocalName == "TreasuryClassif")) {
                                goto TreasuryClassif;
                            }
                            else {
                                if ((Reader.LocalName == "PaymentDesc")) {
                                    goto PaymentDesc;
                                }
                                else {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        Treasury:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaType>Treasury");
            }
            global::Xtee.Core.SerializationMetadata metaTreasury = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.ITreasury>(Reader, "Treasury", "http://producers.arireg.xtee.riik.ee/producer/arireg");
            clazz.Treasury = metaTreasury.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.ITreasury>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("Treasury");
                metaTreasury.NewSerializer(clazz.Treasury).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        Payer:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaType>Payer");
            }
            global::Xtee.Core.SerializationMetadata metaPayer = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IPayer>(Reader, "Payer", "http://producers.arireg.xtee.riik.ee/producer/arireg");
            clazz.Payer = metaPayer.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IPayer>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("Payer");
                metaPayer.NewSerializer(clazz.Payer).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        Receiver:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaType>Receiver");
            }
            global::Xtee.Core.SerializationMetadata metaReceiver = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IReceiver>(Reader, "Receiver", "http://producers.arireg.xtee.riik.ee/producer/arireg");
            clazz.Receiver = metaReceiver.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IReceiver>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("Receiver");
                metaReceiver.NewSerializer(clazz.Receiver).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        Payment:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaType>Payment");
            }
            global::Xtee.Core.SerializationMetadata metaPayment = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IPayment>(Reader, "Payment", "http://producers.arireg.xtee.riik.ee/producer/arireg");
            clazz.Payment = metaPayment.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IPayment>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("Payment");
                metaPayment.NewSerializer(clazz.Payment).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        TreasuryClassif:
            if ((Reader.IsElementNil() == false)) {
                clazz.TreasuryClassif = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("TreasuryClassif")).Value;
            }
            else {
                Reader.Skip();
            }
            goto START;
        PaymentDesc:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MokaType>PaymentDesc");
            }
            clazz.PaymentDesc = new MokaType.PaymentDescType(Reader.ReadElementString("PaymentDesc"));
            goto START;
        }
    }
}
